package ${basePackage}.application.service.${modelNameLowerCamel};

import ${basePackage}.application.dto.${modelNameLowerCamel}.GetResultDTO;
import ${basePackage}.application.seek.IService;
import ${basePackage}.application.seek.ServiceAbstract;
import ${basePackage}.domain.${modelNameLowerCamel}.I${modelNameUpperCamel};
import ${basePackage}.domain.${modelNameLowerCamel}.I${modelNameUpperCamel}Repository;
import ${basePackage}.infrastructure.${modelNameLowerCamel}.${modelNameUpperCamel}Repository;

import org.apache.commons.beanutils.BeanUtils;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by ${author} on ${date}.
 * 描述: 获取${modelName}的业务对象
 */

public class GetService extends ServiceAbstract<Integer, GetResultDTO> implements IService<GetResultDTO> {

    /**
     * ${modelName}的仓储对象
     */
    private I${modelNameUpperCamel}Repository i${modelNameUpperCamel}Repository;

    /**
     * 有参构造，获取传入${modelName}的id
     *
     * @param id ${modelName}的唯一主键
     */
    public GetService(Integer id) {
        super(id);
    }

    /**
     * 获取单个${modelName}的业务操作
     *
     * @return 获取${modelName}返回的信息
     */
    @Override
    protected GetResultDTO process() {
        try {
            i${modelNameUpperCamel}Repository = new ${modelNameUpperCamel}Repository(iUnitOfWork);
            I${modelNameUpperCamel} i${modelNameUpperCamel} = i${modelNameUpperCamel}Repository.get(s);
            GetResultDTO getResultDTO = new GetResultDTO();
            //实体转dto
            try {
                BeanUtils.copyProperties(getResultDTO, i${modelNameUpperCamel});
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
            return getResultDTO;
        } finally {
            iUnitOfWork.close();
        }
    }
}
